package com.lemeng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.lemeng.entity.PageResult;
import com.lemeng.entity.Result;
import com.lemeng.pojo.Para;
import com.lemeng.service.ParaService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("para")
public class ParaController {


    @Reference
    ParaService paraService;


    @GetMapping("findAll")
    public List<Para> findAll(){
        return paraService.findAll();
    }

    @GetMapping("findPage")
    public PageResult<Para> findPage(Integer page, Integer size) {
        return paraService.findPage(page,size);
    }

    @PostMapping("findList")
    public List<Para> findList(@RequestBody Map<String, Object> serchMap) {
        return paraService.findList(serchMap);
    }
    @PostMapping("findPage")
    public PageResult<Para> findPage(Integer page, Integer size,@RequestBody Map<String, Object> serchMap) {
        return paraService.findPage(page,size,serchMap);
    }
    @GetMapping("findById")
    public Para findById(@RequestParam Integer id) {
        return paraService.findById(id);
    }

    @PostMapping("add")
    public Result add(@RequestBody Para para) {
        paraService.add(para);
        return new Result();
    }
    @PostMapping("update")
    public Result update(@RequestBody Para para) {
        paraService.update(para);
        return new Result();
    }

    @GetMapping("delete")
    public Result delete(Integer id) {
        paraService.delete(id);
        return new Result();
    }
    @GetMapping("deleteAll")
    public Result delete(String ids) {

        String[] split = ids.split(",");
        for (String id : split) {
            paraService.delete(Integer.parseInt(id));
        }


        return new Result();
    }


}
